﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using Tong;
public partial class 数据访问控件_后台帮定模板列 : System.Web.UI.Page
{

    /// <summary>
    /// 数据操作通用类 实例 TextData
    /// </summary> 
    public TongUse TextData = new TongUse();

    /// <summary>
    /// 系统安装绝对路径
    /// </summary>
    public string Abs_Path = TongUse.SysPath;
    /// <summary>
    /// 用户存放数据的临时表
    /// </summary>
    DataTable MyDt = new DataTable();



    public string str = "";
    //输出搜索问题
    Repeater MyRe = new Repeater();
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            Response.Write(Request.QueryString["q"]);

        }
        catch
        {

        }
    }
    protected override void CreateChildControls()
    {

        Linq查询DataContext db = new Linq查询DataContext();
        MyRe.DataSource = db.books.Take(10);
        MyRe.ItemTemplate = new MyTemplate();
        MyRe.DataBind();

        Controls.Add(MyRe);

    }


    public override void RenderControl(HtmlTextWriter outhtml)
    {


        MyRe.RenderControl(outhtml);

        base.Render(outhtml);
    }
}

//后台邦定模板
public class MyTemplate : ITemplate
{
    public void InstantiateIn(Control container)
    {
        Literal lbl = new Literal();
        lbl.DataBinding += new EventHandler(lbl_DataBinding);//关键在这里
        container.Controls.Add(lbl);
    }
    private void lbl_DataBinding(object sender, EventArgs e)
    {
        Literal lbl = (Literal)sender;

        lbl.Text = "<a href=\"" + DataBinder.Eval(((RepeaterItem)lbl.NamingContainer).DataItem, "bookname").ToString() + "\">" + DataBinder.Eval(((RepeaterItem)lbl.NamingContainer).DataItem, "bookid").ToString() + "</a>";

    }
}